import PopconfirmButton from '@/components/BizButtons/PopconfirmButton';
import { UseActionControlReturnType } from '@/hooks/useActionControl';
import { DeleteOutlined } from '@ant-design/icons';
import React from 'react';

interface TableRowDelButtonProps {
  actionControl: UseActionControlReturnType;
  record: Record<string, any>;
  /** 所需权限,eg: ['monitor:online:forceLogout'], 传 [] 的视作不需要权限, 默认不需要权限 */
  permissionsRequired?: string[];
  /** 按钮的文字, 默认为空 即只显示图标 */
  buttonText?: string;
  tooltip?: string;
}

const TableRowDelButton: React.FC<TableRowDelButtonProps> = ({
  actionControl,
  record,
  permissionsRequired,
  buttonText = '',
  tooltip = '删除',
}) => {
  return (
    <PopconfirmButton
      tooltip={tooltip}
      key={'delete'}
      permissionsRequired={permissionsRequired}
      buttonText={buttonText}
      title={'删除后不可恢复, 确认删除吗?'}
      buttonProps={{
        danger: true,
        type: 'link',
        icon: <DeleteOutlined />,
        loading: actionControl.loading.value,
      }}
      onConfirm={async () => {
        await actionControl.actions.handleRemoveAction(record);
      }}
    />
  );
};

export default TableRowDelButton;
